<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>moment(String) &#x5E26;&#x683C;&#x5F0F; | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>moment(String) &#x5E26;&#x683C;&#x5F0F;</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>moment(String) 带格式</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/parsing/string-format/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/01-parsing/03-string-format.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment(String, String);
moment(String, String, String);
moment(String, String, Boolean);
moment(String, String, String, Boolean);
</code></pre>

							</div>
<p>&#x5982;&#x679C;&#x77E5;&#x9053;&#x8F93;&#x5165;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5B83;&#x6765;&#x89E3;&#x6790; moment&#x3002;</p>
<pre><code class="language-javascript">moment(&quot;12-25-1995&quot;, &quot;MM-DD-YYYY&quot;);
</code></pre>
<p>&#x89E3;&#x6790;&#x5668;&#x4F1A;&#x5FFD;&#x7565;&#x975E;&#x5B57;&#x6BCD;&#x548C;&#x6570;&#x5B57;&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x56E0;&#x6B64;&#x4EE5;&#x4E0B;&#x4E24;&#x4E2A;&#x90FD;&#x5C06;&#x4F1A;&#x8FD4;&#x56DE;&#x76F8;&#x540C;&#x7684;&#x4E1C;&#x897F;&#x3002;</p>
<pre><code class="language-javascript">moment(&quot;12-25-1995&quot;, &quot;MM-DD-YYYY&quot;);
moment(&quot;12/25/1995&quot;, &quot;MM-DD-YYYY&quot;);
</code></pre>
<p>&#x89E3;&#x6790;&#x4EE4;&#x724C;&#x7C7B;&#x4F3C;&#x4E8E; <code>moment&#xFF03;format</code> &#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x683C;&#x5F0F;&#x5316;&#x4EE4;&#x724C;&#x3002;</p>
<h4>&#x5E74;&#x4EFD;&#x3001;&#x6708;&#x4EFD;&#x3001;&#x65E5;&#x671F;&#x7684;&#x4EE4;&#x724C;</h4>
<p>&#x4EE4;&#x724C;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#x3002;</p>
<table>
<thead>
<tr><th>&#x8F93;&#x5165;</th><th>&#x793A;&#x4F8B;</th><th>&#x63CF;&#x8FF0;</th></tr>
</thead>
<tbody>
<tr><td><code>YYYY</code></td><td><code>2014</code></td><td>4 &#x6216; 2 &#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5E74;&#x4EFD;</td></tr>
<tr><td><code>YY</code></td><td><code>14</code></td><td>2 &#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5E74;&#x4EFD;</td></tr>
<tr><td><code>Y</code></td><td><code>-25</code></td><td>&#x5E26;&#x6709;&#x4EFB;&#x610F;&#x6570;&#x5B57;&#x548C;&#x7B26;&#x53F7;&#x7684;&#x5E74;&#x4EFD;</td></tr>
<tr><td><code>Q</code></td><td><code>1..4</code></td><td>&#x5E74;&#x4EFD;&#x7684;&#x5B63;&#x5EA6;&#x3002;&#x5C06;&#x6708;&#x4EFD;&#x8BBE;&#x7F6E;&#x4E3A;&#x5B63;&#x5EA6;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x6708;</td></tr>
<tr><td><code>M MM</code></td><td><code>1..12</code></td><td>&#x6708;&#x4EFD;&#x6570;&#x5B57;</td></tr>
<tr><td><code>MMM MMMM</code></td><td><code>Jan..December</code></td><td>&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x4E2D;&#x7684;&#x6708;&#x4EFD;&#x540D;&#x79F0;&#xFF0C;&#x7531; <code>moment.locale()</code> &#x8BBE;&#x7F6E;</td></tr>
<tr><td><code>D DD</code></td><td><code>1..31</code></td><td>&#x6708;&#x7684;&#x67D0;&#x5929;</td></tr>
<tr><td><code>Do</code></td><td><code>1st..31st</code></td><td>&#x6708;&#x7684;&#x67D0;&#x5929;&#xFF0C;&#x5E26;&#x5E8F;&#x6570;</td></tr>
<tr><td><code>DDD DDDD</code></td><td><code>1..365</code></td><td>&#x5E74;&#x7684;&#x67D0;&#x5929;</td></tr>
<tr><td><code>X</code></td><td><code>1410715640.579</code></td><td>Unix &#x65F6;&#x95F4;&#x6233;</td></tr>
<tr><td><code>x</code></td><td><code>1410715640579</code></td><td>Unix &#x6BEB;&#x79D2;&#x65F6;&#x95F4;&#x6233;</td></tr>
</tbody>
</table>
<p>&#x4ECE;&#x7248;&#x672C; <strong>2.10.5</strong> &#x5F00;&#x59CB;&#xFF0C;<code>YYYY</code> &#x652F;&#x6301; 2 &#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5E74;&#x4EFD;&#xFF0C;&#x4E14;&#x4F1A;&#x5C06;&#x5176;&#x8F6C;&#x6362;&#x4E3A;&#x63A5;&#x8FD1; 2000 &#x7684;&#x5E74;&#x4EFD;&#xFF08;&#x4E0E; <code>YY</code> &#x76F8;&#x540C;&#xFF09;&#x3002;</p>
<p><code>Y</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.11.1</strong> &#x4E2D;&#x3002;
&#x5B83;&#x5C06;&#x4F1A;&#x5339;&#x914D;&#x4EFB;&#x4F55;&#x6570;&#x5B57;&#xFF0C;&#x6709;&#x7B26;&#x53F7;&#x6216;&#x65E0;&#x7B26;&#x53F7;&#x3002;
&#x5BF9;&#x4E8E;&#x975E; 4 &#x4F4D;&#x6570;&#x5B57;&#x6216;&#x516C;&#x5143;&#x524D;&#x7684;&#x5E74;&#x4EFD;&#x5F88;&#x6709;&#x7528;&#x3002;
&#x5B83;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x4EFB;&#x4F55;&#x5E74;&#x4EFD;&#x3002;</p>
<h4>&#x5468;&#x5E74;&#x3001;&#x661F;&#x671F;&#x3001;&#x5DE5;&#x4F5C;&#x65E5;&#x7684;&#x4EE4;&#x724C;</h4>
<p>&#x5BF9;&#x4E8E;&#x8FD9;&#x4E9B;&#xFF0C;&#x5C0F;&#x5199;&#x5B57;&#x6BCD;&#x4EE4;&#x724C;&#x4F7F;&#x7528;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x611F;&#x77E5;&#x7684;&#x661F;&#x671F;&#x5F00;&#x59CB;&#x5929;&#x6570;&#xFF0C;&#x800C;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x4EE4;&#x724C;&#x4F7F;&#x7528; <a href="javascript:window.open('http://nodejs.cn/s/MkHCug');" target="_blank" rel="nofollow">ISO &#x661F;&#x671F;&#x65E5;&#x671F;</a>&#x5F00;&#x59CB;&#x5929;&#x6570;&#x3002;</p>
<p>&#x4EE4;&#x724C;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#x3002;</p>
<table>
<thead>
<tr><th>&#x8F93;&#x5165;</th><th>&#x793A;&#x4F8B;</th><th>&#x63CF;&#x8FF0;</th></tr>
</thead>
<tbody>
<tr><td><code>gggg</code></td><td><code>2014</code></td><td>&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x7684; 4 &#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5468;&#x5E74;</td></tr>
<tr><td><code>gg</code></td><td><code>14</code></td><td>&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x7684; 2 &#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5468;&#x5E74;</td></tr>
<tr><td><code>w ww</code></td><td><code>1..53</code></td><td>&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x7684;&#x5E74;&#x7684;&#x7B2C;&#x51E0;&#x5468;</td></tr>
<tr><td><code>e</code></td><td><code>0..6</code></td><td>&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x7684;&#x661F;&#x671F;&#x51E0;</td></tr>
<tr><td><code>ddd dddd</code></td><td><code>Mon...Sunday</code></td><td>&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x7684;&#x661F;&#x671F;&#x51E0;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x7531; <code>moment.locale()</code> &#x8BBE;&#x7F6E;</td></tr>
<tr><td><code>GGGG</code></td><td><code>2014</code></td><td>ISO &#x7684; 4 &#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5468;&#x5E74;</td></tr>
<tr><td><code>GG</code></td><td><code>14</code></td><td>ISO &#x7684; 2 &#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5468;&#x5E74;</td></tr>
<tr><td><code>W WW</code></td><td><code>1..53</code></td><td>ISO &#x7684;&#x5E74;&#x7684;&#x7B2C;&#x51E0;&#x5468;</td></tr>
<tr><td><code>E</code></td><td><code>1..7</code></td><td>ISO &#x7684;&#x661F;&#x671F;&#x51E0;</td></tr>
</tbody>
</table>
<h4>&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x611F;&#x77E5;&#x7684;&#x683C;&#x5F0F;</h4>
<p>&#x4F7F;&#x7528; <code>LT LTS L LL LLL LLLL</code> &#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x611F;&#x77E5;&#x7684;&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x3002;
&#x5B83;&#x4EEC;&#x65B0;&#x589E;&#x4E8E; <strong>2.2.1</strong> &#x7248;&#x672C;&#xFF0C;&#x5176;&#x4E2D; <code>LTS</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.8.4</strong>&#x3002;</p>
<p>&#x4EE4;&#x724C;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#x3002;</p>
<table>
<thead>
<tr><th>&#x8F93;&#x5165;</th><th>&#x793A;&#x4F8B;</th><th>&#x63CF;&#x8FF0;</th></tr>
</thead>
<tbody>
<tr><td><code>L</code></td><td><code>04/09/1986</code></td><td>&#x65E5;&#x671F;&#xFF08;&#x4EE5;&#x672C;&#x5730;&#x683C;&#x5F0F;&#xFF09;</td></tr>
<tr><td><code>LL</code></td><td><code>September 4 1986</code></td><td>&#x6708;&#x4EFD;&#x540D;&#x79F0;&#x3001;&#x6708;&#x4EFD;&#x65E5;&#x671F;&#x3001;&#x5E74;&#x4EFD;</td></tr>
<tr><td><code>LLL</code></td><td><code>September 4 1986 8:30 PM</code></td><td>&#x6708;&#x4EFD;&#x540D;&#x79F0;&#x3001;&#x6708;&#x4EFD;&#x65E5;&#x671F;&#x3001;&#x5E74;&#x4EFD;&#x3001;&#x65F6;&#x95F4;</td></tr>
<tr><td><code>LLLL</code></td><td><code>Thursday, September 4 1986 8:30 PM</code></td><td>&#x661F;&#x671F;&#x51E0;&#x3001;&#x6708;&#x4EFD;&#x540D;&#x79F0;&#x3001;&#x6708;&#x4EFD;&#x65E5;&#x671F;&#x3001;&#x5E74;&#x4EFD;&#x3001;&#x65F6;&#x95F4;</td></tr>
<tr><td><code>LT</code></td><td><code>08:30 PM</code></td><td>&#x65F6;&#x95F4;&#xFF08;&#x4E0D;&#x542B;&#x79D2;&#x949F;&#xFF09;</td></tr>
<tr><td><code>LTS</code></td><td><code>08:30:00 PM</code></td><td>&#x65F6;&#x95F4;&#xFF08;&#x542B;&#x79D2;&#x949F;&#xFF09;</td></tr>
</tbody>
</table>
<h4>&#x5C0F;&#x65F6;&#x3001;&#x5206;&#x949F;&#x3001;&#x79D2;&#x79CD;&#x3001;&#x6BEB;&#x79D2;&#x3001;&#x504F;&#x79FB;&#x91CF;&#x7684;&#x4EE4;&#x724C;</h4>
<p>&#x4EE4;&#x724C;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#x3002;</p>
<table>
<thead>
<tr><th>&#x8F93;&#x5165;</th><th>&#x793A;&#x4F8B;</th><th>&#x63CF;&#x8FF0;</th></tr>
</thead>
<tbody>
<tr><td><code>H HH</code></td><td><code>0..23</code></td><td>&#x5C0F;&#x65F6;&#xFF08;24 &#x5C0F;&#x65F6;&#x5236;&#xFF09;</td></tr>
<tr><td><code>h hh</code></td><td><code>1..12</code></td><td>&#x5C0F;&#x65F6;&#xFF08;&#x4F7F;&#x7528; <code>a A</code> &#x7684; 12 &#x5C0F;&#x65F6;&#x5236;&#xFF09;</td></tr>
<tr><td><code>k kk</code></td><td><code>1..24</code></td><td>&#x5C0F;&#x65F6;&#xFF08;&#x4ECE; 1 &#x5230; 24 &#x7684; 24 &#x5C0F;&#x65F6;&#x5236;&#xFF09;</td></tr>
<tr><td><code>a A</code></td><td><code>am pm</code></td><td>&#x4E0A;&#x5348;&#x6216;&#x4E0B;&#x5348;&#xFF08;&#x5355;&#x4E00;&#x5B57;&#x7B26; <code>a p</code> &#x4E5F;&#x88AB;&#x89C6;&#x4E3A;&#x6709;&#x6548;&#xFF09;</td></tr>
<tr><td><code>m mm</code></td><td><code>0..59</code></td><td>&#x5206;&#x949F;</td></tr>
<tr><td><code>s ss</code></td><td><code>0..59</code></td><td>&#x79D2;&#x949F;</td></tr>
<tr><td><code>S SS SSS</code></td><td><code>0..999</code></td><td>&#x5E26;&#x5206;&#x6570;&#x7684;&#x79D2;&#x949F;</td></tr>
<tr><td><code>Z ZZ</code></td><td><code>+12:00</code></td><td>&#x4ECE; UTC &#x504F;&#x79FB;&#x4E3A; <code>+-HH:mm</code>&#x3001;<code>+-HHmm</code> &#x6216; <code>Z</code></td></tr>
</tbody>
</table>
<p>&#x4ECE; <strong>2.10.5</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF1A;&#x957F;&#x5EA6;&#x4E3A; 4 &#x5230; 9 &#x4F4D;&#x7684;&#x5E26;&#x5206;&#x6570;&#x7684;&#x79D2;&#x949F;&#x4EE4;&#x724C;&#x53EF;&#x4EE5;&#x89E3;&#x6790;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x6570;&#x5B57;&#xFF0C;&#x4F46;&#x53EA;&#x4F1A;&#x8003;&#x8651;&#x524D; 3 &#x4E2A;&#x6570;&#xFF08;&#x6BEB;&#x79D2;&#xFF09;&#x3002;
&#x5982;&#x679C;&#x9700;&#x8981;&#x6253;&#x5370;&#x5E26;&#x6709;&#x591A;&#x4F4D;&#x5206;&#x6570;&#x4E14;&#x60F3;&#x8981;&#x6D88;&#x8017;&#x8F93;&#x5165;&#x7684;&#x65F6;&#x95F4;&#xFF0C;&#x5219;&#x4F7F;&#x7528;&#x5B83;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x4EC5;&#x5728;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E2D;&#x89E3;&#x6790;&#x65F6;&#xFF0C;&#x63D0;&#x4F9B;&#x7684; <code>S</code> &#x5B57;&#x7B26;&#x7684;&#x6570;&#x91CF;&#x624D;&#x6709;&#x610F;&#x4E49;&#x3002;
&#x5728;&#x6807;&#x51C6;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;<code>S</code>&#x3001;<code>SS</code>&#x3001;<code>SSS</code>&#x3001;<code>SSSS</code> &#x5747;&#x7B49;&#x6548;&#xFF0C;&#x5E76;&#x89E3;&#x91CA;&#x4E3A;&#x51E0;&#x5206;&#x4E4B;&#x4E00;&#x79D2;&#x3002;
&#x4F8B;&#x5982;&#xFF0C;<code>.12</code> &#x59CB;&#x7EC8;&#x4E3A; 120 &#x6BEB;&#x79D2;&#xFF0C;&#x4F20;&#x5165; <code>SS</code> &#x4E0D;&#x4F1A;&#x5BFC;&#x81F4;&#x5176;&#x88AB;&#x89E3;&#x91CA;&#x4E3A; 12 &#x6BEB;&#x79D2;&#x3002;</p>
<p><code>Z ZZ</code> &#x65B0;&#x589E;&#x4E8E; <strong>1.2.0</strong> &#x7248;&#x672C;&#x3002;</p>
<p><code>S SS SSS</code> &#x65B0;&#x589E;&#x4E8E; <strong>1.6.0</strong> &#x7248;&#x672C;&#x3002;</p>
<p><code>X</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.0.0</strong> &#x7248;&#x672C;&#x3002;</p>
<p><code>k kk</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.18.0</strong> &#x7248;&#x672C;&#x3002;</p>
<p>&#x9664;&#x975E;&#x6307;&#x5B9A;&#x65F6;&#x533A;&#x504F;&#x79FB;&#x91CF;&#xFF0C;&#x5426;&#x5219;&#x89E3;&#x6790;&#x5B57;&#x7B26;&#x4E32;&#x5C06;&#x4F1A;&#x5728;&#x5F53;&#x524D;&#x65F6;&#x533A;&#x4E2D;&#x521B;&#x5EFA;&#x65E5;&#x671F;&#x3002;</p>
<pre><code class="language-js">moment(&quot;2010-10-20 4:30&quot;,       &quot;YYYY-MM-DD HH:mm&quot;);   // &#x89E3;&#x6790;&#x4E3A;&#x5F53;&#x5730;&#x65F6;&#x95F4; 4:30&#x3002;
moment(&quot;2010-10-20 4:30 +0000&quot;, &quot;YYYY-MM-DD HH:mm Z&quot;); // &#x89E3;&#x6790;&#x4E3A; UTC &#x65F6;&#x95F4; 4:30&#x3002;
</code></pre>
<p>&#x5982;&#x679C; moment &#x89E3;&#x6790;&#x7684;&#x8F93;&#x5165;&#x7ED3;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x5219; <code>moment&#xFF03;isValid</code> &#x5C06;&#x4F1A;&#x8FD4;&#x56DE; false&#x3002;</p>
<pre><code class="language-js">moment(&quot;2010 13&quot;,           &quot;YYYY MM&quot;).isValid();     // false&#xFF08;&#x4E0D;&#x662F;&#x771F;&#x5B9E;&#x7684;&#x6708;&#x4EFD;&#xFF09;
moment(&quot;2010 11 31&quot;,        &quot;YYYY MM DD&quot;).isValid();  // false&#xFF08;&#x4E0D;&#x662F;&#x771F;&#x5B9E;&#x7684;&#x65E5;&#x671F;&#xFF09;
moment(&quot;2010 2 29&quot;,         &quot;YYYY MM DD&quot;).isValid();  // false&#xFF08;&#x4E0D;&#x662F;&#x95F0;&#x5E74;&#xFF09;
moment(&quot;2010 notamonth 29&quot;, &quot;YYYY MMM DD&quot;).isValid(); // false&#xFF08;&#x4E0D;&#x662F;&#x771F;&#x5B9E;&#x7684;&#x6708;&#x4EFD;&#x540D;&#x79F0;&#xFF09;
</code></pre>
<p>&#x4ECE; <strong>2.0.0</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x952E;&#x4F5C;&#x4E3A;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x4F20;&#x7ED9; <code>moment()</code> &#x548C; <code>moment.utc()</code>&#x3002;</p>
<pre><code class="language-js">moment(&apos;2012 juillet&apos;, &apos;YYYY MMM&apos;, &apos;fr&apos;);
moment(&apos;2012 July&apos;,    &apos;YYYY MMM&apos;, &apos;en&apos;);
</code></pre>
<p>Moment &#x7684;&#x89E3;&#x6790;&#x5668;&#x975E;&#x5E38;&#x5BBD;&#x677E;&#xFF0C;&#x8FD9;&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x4E0D;&#x671F;&#x671B;&#x6216;&#x610F;&#x5916;&#x7684;&#x884C;&#x4E3A;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x53EF;&#x4EE5;&#x89C2;&#x5BDF;&#x5230;&#x4EE5;&#x4E0B;&#x884C;&#x4E3A;&#xFF1A;</p>
<pre><code class="language-javascript">moment(&apos;2016 is a date&apos;, &apos;YYYY-MM-DD&apos;).isValid() //true, 2016 &#x88AB;&#x5339;&#x914D;&#x3002;
</code></pre>
<p>&#x5728; <strong>2.13.0</strong> &#x4E4B;&#x524D;&#xFF0C;&#x89E3;&#x6790;&#x5668;&#x4F1A;&#x8868;&#x73B0;&#x51FA;&#x4EE5;&#x4E0B;&#x884C;&#x4E3A;&#x3002;
&#x8FD9;&#x5DF2;&#x5F97;&#x5230;&#x7EA0;&#x6B63;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;I am spartacus&apos;, &apos;h:hh A&apos;).isValid();     //true - &apos;am&apos; &#x548C; &apos;A&apos; &#x6807;&#x5FD7;&#x5339;&#x914D;&#x3002;
</code></pre>
<p>&#x4ECE; <strong>2.3.0</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x53EF;&#x4EE5;&#x4E3A;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x4EE5;&#x4F7F; Moment &#x4F7F;&#x7528;&#x4E25;&#x683C;&#x7684;&#x89E3;&#x6790;&#x3002;
&#x4E25;&#x683C;&#x7684;&#x89E3;&#x6790;&#x8981;&#x6C42;&#x683C;&#x5F0F;&#x548C;&#x8F93;&#x5165;&#x5B8C;&#x5168;&#x5339;&#x914D;&#xFF0C;&#x5305;&#x62EC;&#x5206;&#x9694;&#x7B26;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;It is 2012-05-25&apos;, &apos;YYYY-MM-DD&apos;).isValid();       // true
moment(&apos;It is 2012-05-25&apos;, &apos;YYYY-MM-DD&apos;, true).isValid(); // false
moment(&apos;2012-05-25&apos;,       &apos;YYYY-MM-DD&apos;, true).isValid(); // true
moment(&apos;2012.05.25&apos;,       &apos;YYYY-MM-DD&apos;, true).isValid(); // false
</code></pre>
<p>&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x4F7F;&#x7528;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x548C;&#x4E25;&#x683C;&#x6027;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2012-10-14&apos;, &apos;YYYY-MM-DD&apos;, &apos;fr&apos;, true);
</code></pre>
<p>&#x4E25;&#x683C;&#x7684;&#x89E3;&#x6790;&#x901A;&#x5E38;&#x662F;&#x6700;&#x597D;&#x7684;&#x89E3;&#x6790;&#x9009;&#x9879;&#x3002;
&#x6709;&#x5173;&#x9009;&#x62E9;&#x4E25;&#x683C;&#x8FD8;&#x662F;&#x5BBD;&#x677E;&#x89E3;&#x6790;&#x7684;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#xFF0C;&#x53C2;&#x9605;<a href="javascript:window.open('http://nodejs.cn/s/vPwJST');" target="_blank" rel="nofollow">&#x89E3;&#x6790;&#x6307;&#x5357;</a>&#x3002;</p>
<h4>&#x89E3;&#x6790;&#x4E24;&#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5E74;&#x4EFD;</h4>
<p>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;68 &#x4E4B;&#x524D;&#x7684;&#x4E24;&#x4F4D;&#x6570;&#x5B57;&#x7684;&#x5E74;&#x4EFD;&#x4F1A;&#x88AB;&#x5047;&#x5B9A;&#x662F; 1900 &#x5E74;&#x4EE3;&#xFF0C;&#x800C; 68 &#x6216;&#x4E4B;&#x540E;&#x7684;&#x5E74;&#x4EFD;&#x5219;&#x4F1A;&#x88AB;&#x5047;&#x5B9A;&#x662F; 2000 &#x5E74;&#x4EE3;&#x3002;
&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x66FF;&#x6362; <code>moment.parseTwoDigitYear</code> &#x65B9;&#x6CD5;&#x6765;&#x66F4;&#x6539;&#x3002;
&#x8BE5;&#x65B9;&#x6CD5;&#x7684;&#x552F;&#x4E00;&#x53C2;&#x6570;&#x662F;&#x5305;&#x542B;&#x7528;&#x6237;&#x8F93;&#x5165;&#x7684;&#x4E24;&#x4F4D;&#x5E74;&#x4EFD;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5E76;&#x4E14;&#x5E94;&#x4EE5;&#x6574;&#x6570;&#x5F62;&#x5F0F;&#x8FD4;&#x56DE;&#x5E74;&#x4EFD;&#x3002;</p>
<pre><code class="language-javascript">moment.parseTwoDigitYear = function(yearString) {
    return parseInt(yearString) + 2000;
}
</code></pre>
<h4>&#x89E3;&#x6790;&#x80F6;&#x5408;&#x7684;&#x5C0F;&#x65F6;&#x548C;&#x5206;&#x949F;</h4>
<p>&#x4ECE; <strong>2.11.0</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x652F;&#x6301;&#x89E3;&#x6790; <code>hmm</code>&#x3001;<code>Hmm</code>&#x3001;<code>hmmss</code> &#x548C; <code>Hmmss</code>&#xFF1A;</p>
<pre><code class="language-javascript">moment(&quot;123&quot;, &quot;hmm&quot;).format(&quot;HH:mm&quot;) === &quot;01:23&quot;
moment(&quot;1234&quot;, &quot;hmm&quot;).format(&quot;HH:mm&quot;) === &quot;12:34&quot;
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment(String, String);
moment(String, String, String);
moment(String, String, Boolean);
moment(String, String, String, Boolean);
</code></pre>

							</div>
<p>If you know the format of an input string, you can use that to parse a moment.</p>
<pre><code class="language-javascript">moment(&quot;12-25-1995&quot;, &quot;MM-DD-YYYY&quot;);
</code></pre>
<p>The parser ignores non-alphanumeric characters, so both of the following will return the same thing.</p>
<pre><code class="language-javascript">moment(&quot;12-25-1995&quot;, &quot;MM-DD-YYYY&quot;);
moment(&quot;12/25/1995&quot;, &quot;MM-DD-YYYY&quot;);
</code></pre>
<p>The parsing tokens are similar to the formatting tokens used in <code>moment#format</code>.</p>
<h4>Year, month, and day tokens</h4>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr><th>Input</th><th>Example</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>YYYY</code></td><td><code>2014</code></td><td>4 or 2 digit year</td></tr>
<tr><td><code>YY</code></td><td><code>14</code></td><td>2 digit year</td></tr>
<tr><td><code>Y</code></td><td><code>-25</code></td><td>Year with any number of digits and sign</td></tr>
<tr><td><code>Q</code></td><td><code>1..4</code></td><td>Quarter of year. Sets month to first month in quarter.</td></tr>
<tr><td><code>M MM</code></td><td><code>1..12</code></td><td>Month number</td></tr>
<tr><td><code>MMM MMMM</code></td><td><code>Jan..December</code></td><td>Month name in locale set by <code>moment.locale()</code></td></tr>
<tr><td><code>D DD</code></td><td><code>1..31</code></td><td>Day of month</td></tr>
<tr><td><code>Do</code></td><td><code>1st..31st</code></td><td>Day of month with ordinal</td></tr>
<tr><td><code>DDD DDDD</code></td><td><code>1..365</code></td><td>Day of year</td></tr>
<tr><td><code>X</code></td><td><code>1410715640.579</code></td><td>Unix timestamp</td></tr>
<tr><td><code>x</code></td><td><code>1410715640579</code></td><td>Unix ms timestamp</td></tr>
</tbody>
</table>
<p><code>YYYY</code> from version <strong>2.10.5</strong> supports 2 digit years, and converts them to a year
near 2000 (same as <code>YY</code>).</p>
<p><code>Y</code> was added in <strong>2.11.1</strong>. It will match any number, signed or unsigned. It is useful for years that are not 4 digits or are before the common era. It can be used for any year.</p>
<h4>Week year, week, and weekday tokens</h4>
<p>For these, the lowercase tokens use the locale aware week start days, and the uppercase tokens use the <a href="javascript:window.open('https://en.wikipedia.org/wiki/ISO_week_date');" target="_blank" rel="nofollow">ISO week date</a> start days.</p>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr><th>Input</th><th>Example</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>gggg</code></td><td><code>2014</code></td><td>Locale 4 digit week year</td></tr>
<tr><td><code>gg</code></td><td><code>14</code></td><td>Locale 2 digit week year</td></tr>
<tr><td><code>w ww</code></td><td><code>1..53</code></td><td>Locale week of year</td></tr>
<tr><td><code>e</code></td><td><code>0..6</code></td><td>Locale day of week</td></tr>
<tr><td><code>ddd dddd</code></td><td><code>Mon...Sunday</code></td><td>Day name in locale set by <code>moment.locale()</code></td></tr>
<tr><td><code>GGGG</code></td><td><code>2014</code></td><td>ISO 4 digit week year</td></tr>
<tr><td><code>GG</code></td><td><code>14</code></td><td>ISO 2 digit week year</td></tr>
<tr><td><code>W WW</code></td><td><code>1..53</code></td><td>ISO week of year</td></tr>
<tr><td><code>E</code></td><td><code>1..7</code></td><td>ISO day of week</td></tr>
</tbody>
</table>
<h4>Locale aware formats</h4>
<p>Locale aware date and time formats are also available using <code>LT LTS L LL LLL LLLL</code>. They were added in version <strong>2.2.1</strong>, except <code>LTS</code> which was added
<strong>2.8.4</strong>.</p>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr><th>Input</th><th>Example</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>L</code></td><td><code>04/09/1986</code></td><td>Date (in local format)</td></tr>
<tr><td><code>LL</code></td><td><code>September 4 1986</code></td><td>Month name, day of month, year</td></tr>
<tr><td><code>LLL</code></td><td><code>September 4 1986 8:30 PM</code></td><td>Month name, day of month, year, time</td></tr>
<tr><td><code>LLLL</code></td><td><code>Thursday, September 4 1986 8:30 PM</code></td><td>Day of week, month name, day of month, year, time</td></tr>
<tr><td><code>LT</code></td><td><code>08:30 PM</code></td><td>Time (without seconds)</td></tr>
<tr><td><code>LTS</code></td><td><code>08:30:00 PM</code></td><td>Time (with seconds)</td></tr>
</tbody>
</table>
<h4>Hour, minute, second, millisecond, and offset tokens</h4>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr><th>Input</th><th>Example</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>H HH</code></td><td><code>0..23</code></td><td>Hours (24 hour time)</td></tr>
<tr><td><code>h hh</code></td><td><code>1..12</code></td><td>Hours (12 hour time used with <code>a A</code>.)</td></tr>
<tr><td><code>k kk</code></td><td><code>1..24</code></td><td>Hours (24 hour time from 1 to 24)</td></tr>
<tr><td><code>a A</code></td><td><code>am pm</code></td><td>Post or ante meridiem (Note the one character <code>a p</code> are also considered valid)</td></tr>
<tr><td><code>m mm</code></td><td><code>0..59</code></td><td>Minutes</td></tr>
<tr><td><code>s ss</code></td><td><code>0..59</code></td><td>Seconds</td></tr>
<tr><td><code>S SS SSS</code></td><td><code>0..999</code></td><td>Fractional seconds</td></tr>
<tr><td><code>Z ZZ</code></td><td><code>+12:00</code></td><td>Offset from UTC as <code>+-HH:mm</code>, <code>+-HHmm</code>, or <code>Z</code></td></tr>
</tbody>
</table>
<p>From version <strong>2.10.5</strong>: fractional second tokens length 4 up to 9 can parse
any number of digits, but will only consider the top 3 (milliseconds). Use if
you have the time printed with many fractional digits and want to consume the
input.</p>
<p>Note that the number of <code>S</code> characters provided is only relevant when parsing in strict mode.
In standard mode, <code>S</code>, <code>SS</code>, <code>SSS</code>, <code>SSSS</code> are all equivalent, and interpreted as fractions of a second.
For example, <code>.12</code> is always 120 milliseconds, passing <code>SS</code> will not cause it to be interpreted as 12 milliseconds.</p>
<p><code>Z ZZ</code> were added in version <strong>1.2.0</strong>.</p>
<p><code>S SS SSS</code> were added in version <strong>1.6.0</strong>.</p>
<p><code>X</code> was added in version <strong>2.0.0</strong>.</p>
<p><code>k kk</code> was added in version <strong>2.18.0</strong></p>
<p>Unless you specify a time zone offset, parsing a string will create a date in the current time zone.</p>
<pre><code class="language-js">moment(&quot;2010-10-20 4:30&quot;,       &quot;YYYY-MM-DD HH:mm&quot;);   // parsed as 4:30 local time
moment(&quot;2010-10-20 4:30 +0000&quot;, &quot;YYYY-MM-DD HH:mm Z&quot;); // parsed as 4:30 UTC
</code></pre>
<p>If the moment that results from the parsed input does not exist, <code>moment#isValid</code> will return false.</p>
<pre><code class="language-js">moment(&quot;2010 13&quot;,           &quot;YYYY MM&quot;).isValid();     // false (not a real month)
moment(&quot;2010 11 31&quot;,        &quot;YYYY MM DD&quot;).isValid();  // false (not a real day)
moment(&quot;2010 2 29&quot;,         &quot;YYYY MM DD&quot;).isValid();  // false (not a leap year)
moment(&quot;2010 notamonth 29&quot;, &quot;YYYY MMM DD&quot;).isValid(); // false (not a real month name)
</code></pre>
<p>As of version <strong>2.0.0</strong>, a locale key can be passed as the third parameter to <code>moment()</code> and <code>moment.utc()</code>.</p>
<pre><code class="language-js">moment(&apos;2012 juillet&apos;, &apos;YYYY MMM&apos;, &apos;fr&apos;);
moment(&apos;2012 July&apos;,    &apos;YYYY MMM&apos;, &apos;en&apos;);
</code></pre>
<p>Moment&apos;s parser is very forgiving, and this can lead to undesired/unexpected behavior.</p>
<p>For example, the following behavior can be observed:</p>
<pre><code class="language-javascript">moment(&apos;2016 is a date&apos;, &apos;YYYY-MM-DD&apos;).isValid() //true, 2016 was matched
</code></pre>
<p>Previous to <strong>2.13.0</strong> the parser exhibited the following behavior. This has been corrected.</p>
<pre><code class="language-javascript">moment(&apos;I am spartacus&apos;, &apos;h:hh A&apos;).isValid();     //true - the &apos;am&apos; matches the &apos;A&apos; flag.
</code></pre>
<p>As of version <strong>2.3.0</strong>, you may specify a boolean for the last argument to make Moment use strict parsing. Strict parsing requires that the format and input match exactly, <em>including delimeters</em>.</p>
<pre><code class="language-javascript">moment(&apos;It is 2012-05-25&apos;, &apos;YYYY-MM-DD&apos;).isValid();       // true
moment(&apos;It is 2012-05-25&apos;, &apos;YYYY-MM-DD&apos;, true).isValid(); // false
moment(&apos;2012-05-25&apos;,       &apos;YYYY-MM-DD&apos;, true).isValid(); // true
moment(&apos;2012.05.25&apos;,       &apos;YYYY-MM-DD&apos;, true).isValid(); // false
</code></pre>
<p>You can use both locale and strictness.</p>
<pre><code class="language-javascript">moment(&apos;2012-10-14&apos;, &apos;YYYY-MM-DD&apos;, &apos;fr&apos;, true);
</code></pre>
<p>Strict parsing is frequently the best parsing option. For more information about choosing strict vs forgiving parsing, see the <a href="index3.html#/parsing/" target="_blank" rel="nofollow">parsing guide.</a></p>
<h4>Parsing two digit years</h4>
<p>By default, two digit years above 68 are assumed to be in the 1900&apos;s and years 68 or below are assumed to be in the 2000&apos;s. This can be changed by replacing the <code>moment.parseTwoDigitYear</code> method. The only argument of this method is a string containing the two years input by the user, and should return the year as an integer.</p>
<pre><code class="language-javascript">moment.parseTwoDigitYear = function(yearString) {
    return parseInt(yearString) + 2000;
}
</code></pre>
<h4>Parsing glued hour and minutes</h4>
<p>From version <strong>2.11.0</strong> parsing <code>hmm</code>, <code>Hmm</code>, <code>hmmss</code> and <code>Hmmss</code> is supported:</p>
<pre><code class="language-javascript">moment(&quot;123&quot;, &quot;hmm&quot;).format(&quot;HH:mm&quot;) === &quot;01:23&quot;
moment(&quot;1234&quot;, &quot;hmm&quot;).format(&quot;HH:mm&quot;) === &quot;12:34&quot;
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>